import { BroadCastCall } from "../../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { Cache } from "../../../cache/Cache";
import { SArenaCrossOpen } from "../../../../../Message/Public/SArenaCrossOpen";
import { EArenaProcess } from "../../../../../Message/Public/EArenaProcess";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { ClockManager } from "../../../manager/ClockManager";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Language } from "../../../../../extend/language/Language";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
type int = number;
//class ArenaCrossWillOpenCommand
    
    export  class ArenaCrossWillOpenCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            if (!Cache.instance.arenaCross.isOpen) 
            {
                Cache.instance.arenaCross.isWillOpen = true;
            }
            this.arenaCrossOpen = arg1.messageBase as SArenaCrossOpen;
            Cache.instance.arenaCross.willOpen = this.arenaCrossOpen;
            if (Cache.instance.arenaCross.arenaCrossInfo) 
            {
                Cache.instance.arenaCross.arenaCrossInfo.process = this.arenaCrossOpen.process;
            }
            if (this.arenaCrossOpen.process == EArenaProcess._EArenaGroupMatch1 || this.arenaCrossOpen.process == EArenaProcess._EArenaGroupMatch2 || this.arenaCrossOpen.process == EArenaProcess._EArenaFinalMatch1 || this.arenaCrossOpen.process == EArenaProcess._EArenaFinalMatch2) 
            {
                this.tipLater(7);
                this.tipLater(3);
                this.tipLater(1);
            }
            NetDispatcher.dispatchCmd(ServerCommand.ArenaCrossWillOpenCommand, null);
            return;
        }

        /* internal  */tipLater(arg1: int): void
        {
            var loc1=NaN;
            var loc2=NaN;
            var loc3=NaN;
            var loc4=NaN;
            if (this.arenaCrossOpen) 
            {
                loc1 = ClockManager.instance.nowDate.time;
                loc2 = this.arenaCrossOpen.openDt.time;
                if ((loc4 = (loc3 = loc2 - arg1 * 60 * 1000) - loc1) > 0) 
                {
                    flash.utils.setTimeout(this.judgeGroupMatchInArenaCross, loc4);
                }
            }
            return;
        }

        /* internal  */judgeGroupMatchInArenaCross(): void
        {
            var loc2=null;
            var loc1=Cache.instance.arenaCross.arenaCrossInfo;
            if (loc1 && loc1.myProcess >= loc1.process && !GameMapUtil.curMapState.isArenaCross && !GameMapUtil.curMapState.isArenaCrossWaitingRoom && !this._alert) 
            {
                Alert.buttonWidth = 70;
                Alert.yesLabel = Language.getString(44213);
                Alert.okLabel = Language.getString(57319);
                loc2 = Language.getString(44271);
                if (this.arenaCrossOpen.process == EArenaProcess._EArenaFinalMatch1 || this.arenaCrossOpen.process == EArenaProcess._EArenaFinalMatch2) 
                {
                    loc2 = Language.getString(44365);
                }
                this._alert = Alert.show(loc2, null, Alert.OK | Alert.YES, null, this.chooseAlert);
            }
            return;
        }

        /* internal  */chooseAlert(arg1: int): void
        {
            var loc1=Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectArenaCross);
            if (arg1 != Alert.YES) 
            {
                if (arg1 == Alert.OK) 
                {
                    AIManager.onAIControl(loc1, AIType.AI_Convey);
                }
            }
            else 
            {
                AIManager.onAutoPathAIControl(loc1);
            }
            this._alert = null;
            return;
        }

        private /* var */arenaCrossOpen: SArenaCrossOpen;

        private /* var */_alert: Object /* flash.display.Sprite */;
    }
